﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using RCREEE.Library.Entities;

namespace RCREEE.Library
{
    public partial class DataManager
    {
        #region Public Method
/// <summary>
/// Select RenewableEnergy from CountryDetails 
/// </summary>
/// <param name="LanguageCode">get from function of CountryDetails class</param>
/// <returns> Datatable 3 Cloumns Name of Country ,Feild ,Comment</returns>
        public static DataTable SelectRenewableEnergey(int LanguageCode)
        {
            try
            {
                _Adapter.SelectCommand.CommandText = "GetRenewableEnergy";
                _Adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Adapter.SelectCommand.Parameters.Clear();

                _Adapter.SelectCommand.Parameters.Add("@LanguageCode", SqlDbType.Int).Value = LanguageCode;
                 _DataTable = new DataTable();
                _Adapter.Fill(_DataTable);

                return _DataTable;
            }
            catch (Exception e)
            {
                return _DataTable;
            }
        }

        public static DataTable SelectCountryRenewableEnergey(int CountryId)
        {
            try
            {
                _Adapter.SelectCommand.CommandText = "GetCountryRenewableEnergy";
                _Adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Adapter.SelectCommand.Parameters.Clear();

                _Adapter.SelectCommand.Parameters.Add("@CountryId", SqlDbType.Int).Value = CountryId;
                _DataTable = new DataTable();
                _Adapter.Fill(_DataTable);
                if (_DataTable.Rows.Count == 0)
                    _DataTable.Rows.Add(_DataTable.NewRow());
                return _DataTable;
            }
            catch (Exception e)
            {
                return _DataTable;
            }
        }

      
        /// <summary>
        /// Select EnergyEfficiency from CountryDetails table
        /// </summary>
        /// <param name="LanguageCode">get from function of CountryDetails class</param>
        /// <returns> Datatable 3 Cloumns Name of Country ,Feild ,Comment</returns>
        public static DataTable SelectEnergyEfficiency(int LanguageCode)
        {

            try
            {
                _Adapter.SelectCommand.CommandText = "GetEnergyEfficiency";
                _Adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Adapter.SelectCommand.Parameters.Clear();

                _Adapter.SelectCommand.Parameters.Add("@LanguageCode", SqlDbType.Int).Value = LanguageCode;
                _DataTable = new DataTable();
                _Adapter.Fill(_DataTable);

             

                return _DataTable;
            }
            catch (Exception e)
            {
                return _DataTable;
            }
        }
        public static DataTable SelectCountryEnergyEfficiency(int CountryId)
        {

            try
            {
                _Adapter.SelectCommand.CommandText = "GetCountryEnergyEfficiency";
                _Adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Adapter.SelectCommand.Parameters.Clear();

                _Adapter.SelectCommand.Parameters.Add("@CountryId", SqlDbType.Int).Value =CountryId;
                _DataTable = new DataTable();
                _Adapter.Fill(_DataTable);
                  if(_DataTable.Rows.Count==0)
                      _DataTable.Rows.Add(_DataTable.NewRow());
                return _DataTable;
            }
            catch (Exception e)
            {
                return _DataTable;
            }
        }

        public static int UpdateRenewable(List<CountryDetails> CD)
        {
            try{
            for (int i = 0; i < CD.Count; i++)
            {
                _Adapter.SelectCommand.CommandText = "UpdateRenewableEnergy";
                _Adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Adapter.SelectCommand.Parameters.Clear();
                _Adapter.SelectCommand.Parameters.Add("@CountryId", SqlDbType.Int).Value = CD[i].CountryId;
                _Adapter.SelectCommand.Parameters.Add("@LanguageCode", SqlDbType.Int).Value = CD[i].LanguageCode;
                _Adapter.SelectCommand.Parameters.Add("@RenewableEnergyContributionRate", SqlDbType.Float).Value = CD[i].RenewableEnergyContributionRate;
                _Adapter.SelectCommand.Parameters.Add("@RenewableEnergyContributionRateComment", SqlDbType.NVarChar).Value = CD[i].RenewableEnergyContributionRateComment;
                OpenConnection();
               int roweffect = Convert.ToInt32(_Adapter.SelectCommand.ExecuteNonQuery());
                CloseConnection();

            }
            return 1;
            }
            catch(Exception)
            {return 0;}
        }
        public static int UpdateEnergyEfficiency(List<CountryDetails> CD)
        {
            try
            {
                for (int i = 0; i < CD.Count; i++)
                {
                    _Adapter.SelectCommand.CommandText = "UpdateEnergyEfficiency";
                    _Adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                    _Adapter.SelectCommand.Parameters.Clear();
                    _Adapter.SelectCommand.Parameters.Add("@CountryId", SqlDbType.Int).Value = CD[i].CountryId;
                    _Adapter.SelectCommand.Parameters.Add("@LanguageCode", SqlDbType.Int).Value = CD[i].LanguageCode;
                    _Adapter.SelectCommand.Parameters.Add("@EnergyEfficiencyContributionRate", SqlDbType.Float).Value = CD[i].EnergyEfficiencyContributionRate;
                    _Adapter.SelectCommand.Parameters.Add("@EnergyEfficiencyContributionRateComment", SqlDbType.NVarChar).Value = CD[i].EnergyEfficiencyContributionRateComment;
                    OpenConnection();
                    int roweffect = Convert.ToInt32(_Adapter.SelectCommand.ExecuteNonQuery());
                    CloseConnection();

                }
                return 1;
            }
            catch (Exception)
            { return 0; }
        }

        #endregion
    }
}
